//
//  ToolViewController.m
//  e律师
//
//  Created by 韦淋 on 2017/5/18.
//  Copyright © 2017年 test. All rights reserved.
//

#import "ToolViewController.h"


@interface ToolViewController ()
@property (nonatomic, strong) NSArray *data;
@end

@implementation ToolViewController
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    //    self.automaticallyAdjustsScrollViewInsets = false;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.barTitleLable.text = @"应用工具";
    self.data = [NSArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    [self getUI];
    [self getData];
}


#pragma mark = Private Method
- (void)getData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetworkingManager getUrl:AVERAGEPAY_URL dic:nil Succeed:^(id responseData) {
        NSLog(@"success :%@",responseData);
        self.data = responseData[@"result"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } failure:^(NSError *error) {
        NSLog(@"error :%@",error);
        [MBProgressHUD showError:@"网络连接失败"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}
- (void)getUI{
    UIImageView *topImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 200)];
    topImage.image = [UIImage imageNamed:@"gj_banner.jpg"];
    [self.view addSubview:topImage];
    
    NSArray *titleArray = @[@"贷款利息",@"工伤赔偿",@"人身损害赔偿",@"律师费",@"诉讼费",@"违约金"];
    NSArray *imageArray = @[@"gj_01",@"gj_02",@"gj_07",@"gj_04",@"gj_05",@"gj_06"];
    CGFloat width = (CGFloat)(SCREEN_WIDTH - 13)/3;
    for (int i = 0; i < titleArray.count; i++) {
        [self.view layoutIfNeeded];
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(3+width*(i%3)+3*(i%3), 3+width*(i/3)+3*(i/3) + 264, width, width)];
        button.tag = 1000+i;
        [button setTitle:titleArray[i] forState:0];
        button.titleLabel.font = [UIFont systemFontOfSize:13];
        [button setTitleColor:[UIColor blackColor] forState:0];
        [button setImage:[UIImage imageNamed:imageArray[i]] forState:0];
        button.layer.borderColor = [UIColor lightGrayColor].CGColor;
        button.layer.borderWidth = 0.5;
        [button layoutButtonWithEdgInsetsStyle:WxyButtonEdgeInsetsStyleImageTop imageTitleSpacing:20];
        [button addTarget:self action:@selector(chooseView:) forControlEvents:UIControlEventTouchUpInside];
        [self.view insertSubview:button atIndex:0];
    }

}

#pragma mark - ButtonTarget
- (void)chooseView:(UIButton *)sender{
    NSLog(@"tag = %ld",sender.tag);
    if (sender.tag == 1002) {
        [MBProgressHUD showError:@"敬请期待"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }
    else{
        ToolsController *tools = [[ToolsController alloc] init];
        tools.log = sender.tag;
        tools.averagePay = self.data;
        [self.navigationController pushViewController:tools animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
